import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

import 'order_list_widget.dart';

///1.全部订单
///2.发票管理
class OrderList extends StatefulWidget {
  ///[label] 1 全部订单  ,2 发票管理
  final Map<String, dynamic> arguments;

  const OrderList({Key key, this.arguments}) : super(key: key);

  @override
  _OrderListState createState() => _OrderListState();
}

class _OrderListState extends State<OrderList>
    with SingleTickerProviderStateMixin {
  final List<String> _tabNames1 = ["全部", "已报案", "待定损", "定损争议"];
  PageController _pageController = PageController(initialPage: 0);
  TabController _tabController;
  String _label = "1";
  List<String> _tabs;
  String _title;

  // @override
  // bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    _label = widget.arguments["label"];
    _tabs = _tabNames1;
    _title = "全部订单";

    _tabController = new TabController(vsync: this, length: _tabs.length);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFFf0f0f0),
      appBar: customAppBar(context, title: _title, elevation: 0.0),
      body: _body(),
    );
  }

  _body() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Container(
          // color: Colors.white,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Expanded(
                flex: 1,
                child: TabBar(
                  onTap: (index) {
                    if (!mounted) return;
                    _pageController.jumpToPage(index);
                  },
                  isScrollable: true,
                  controller: _tabController,
                  indicatorColor: Color(0xFF00c65f),
                  indicatorWeight: setWidth(2),
                  indicatorSize: TabBarIndicatorSize.label,
                  labelColor: Color(0xFF00c65f),
                  unselectedLabelColor: Color(0xFF323232),
                  tabs: _tabs.map((e) => Tab(text: e)).toList(),
                ),
              ),
            ],
          ),
        ),
        Expanded(
          child: PageView.builder(
            key: const Key('pageView'),
            itemCount: _tabs.length,
            onPageChanged: _onPageChange,
            controller: _pageController,
            itemBuilder: (BuildContext context, int index) {
              Map<String, dynamic> arguments = {"title": "${_tabs[index]}"};
              return OrderListWidget();
            },
          ),
        )
      ],
    );
  }

  _onPageChange(int index) {
    _tabController.animateTo(index);
  }

  getMargin() {
    return EdgeInsets.only(
        left: setWidth(20),
        right: setWidth(20),
        top: setWidth(15),
        bottom: setWidth(15));
  }

  getLine() {
    return Container(
      height: setWidth(42),
      width: setWidth(1),
      color: Colors.black,
    );
  }
}
